package com.lizemin.socketIo;

import com.corundumstudio.socketio.SocketIOServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.PreDestroy;

@Slf4j
@SpringBootApplication
public class SocketIoApplication implements CommandLineRunner {

    @Autowired
    private SocketIOServer socketIOServer;

    public static void main(String[] args) {
        SpringApplication.run(SocketIoApplication.class, args);
    }

    @Override
    public void run(String... args) {
        // 启动 SocketIOServer
        socketIOServer.start();
        log.info("Socket.IO 服务器已启动，端口: 9092");
    }

    @PreDestroy
    public void stop() {
        // 关闭 SocketIOServer
        if (socketIOServer != null) {
            socketIOServer.stop();
        }
    }


}
